package com.zzh.api.init;

import com.zzh.api.init.model.InitModel;
import com.zzh.api.init.service.InitApiService;
import com.zzh.api.model.CommonResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "init")
public class InitApiController {
    @Resource(name = "apiService")
    private InitApiService apiService;

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public String test(Model model) {
        System.out.println("-----------------------");
        model.addAttribute("{\"key\":\"value\"}");
        if (apiService != null) {
            InitModel query = apiService.query();
            if (query != null) {
                System.out.println(query);
            } else {
                System.out.println("--------------query is null");
            }
        } else {
            System.out.println("--------------apiService is null");
        }

        return "------------";
    }

    @RequestMapping(value = "/init", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<InitModel> apiInit() {
        InitModel query = apiService.query();
        return CommonResult.setResultOk(query);
    }


}
